#include "front/text_normalize.h"

using namespace std;
using namespace ppspeech;

const wregex mcWregexSlash(L"((-?)(\\d+)(\\.\\d+)?\\s*)(/\\s*(-?)(\\d+)(\\.\\d+)?)+");

// XX/XX/XX		9/10/11 --> 九比十比十一
// XX/XX		1/3 --> 三分之一
void TextNormalizer::TnReSlash(wstring* fpInWsentence, const LanguageEnum fcInLanguage)
{
	wsmatch tWsmatch;
	while (regex_search(*fpInWsentence, tWsmatch, mcWregexSlash)) {
		string tStrReplace = "";
		string tStrSlash = wstring2utf8string(tWsmatch[0]);		//匹配到斜杠的字符串
		StrReplace(tStrSlash, " ", "");
		
		vector<string> tItemSlash = StrSplit(tStrSlash, "/");
		size_t tItemTotal = tItemSlash.size();

		//超过两项的情况，__/__/__
		if(tItemTotal > 2) {
			if(tItemTotal == 3 && tItemSlash[0].length()==4 && tItemSlash[1].length()==2 && tItemSlash[2].length()==2) {	//年月日
				tStrReplace = ReplaceMethod(tItemSlash, (fcInLanguage==LANG_EN)?RME_en_chinesedate:RME_zh_chinesedate);
			}
			else {	//采用比值读法。
				tStrReplace = ReplaceMethod(tItemSlash, (fcInLanguage==LANG_EN)?RME_en_colon_ratio:RME_zh_colon_ratio);
			}
		}
		//等于2项的情况，__/__，采用分数读法。
		else if(tItemTotal == 2) {
			tStrReplace = ReplaceMethod(tItemSlash, (fcInLanguage==LANG_EN)?RME_en_fraction:RME_zh_fraction);
		}

		WstrReplacePosition(fpInWsentence, tWsmatch.position(0), tWsmatch.length(0), utf8string2wstring(tStrReplace));
	}
}
